//
//  FirstScrollController.m
//  jizhiyunduan
//
//  Created by 鞠超 on 16/4/13.
//  Copyright © 2016年 JC. All rights reserved.
//

#import "FirstScrollController.h"

#define kfirstScrollNum 3
@interface FirstScrollController ()

@end

@implementation FirstScrollController

@synthesize scrollBG,pageCol;

- (void)viewDidLoad {
    [super viewDidLoad];
    scrollBG=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    scrollBG.delegate = self;
    scrollBG.showsHorizontalScrollIndicator = NO;
    scrollBG.contentSize = CGSizeMake(SCREEN_WIDTH * kfirstScrollNum, SCREEN_HEIGHT);
    scrollBG.pagingEnabled = YES;
    [self.view addSubview:scrollBG];
    
    for (int i = 0; i < kfirstScrollNum; i++) {
        UIImageView *imgInfo=[[UIImageView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH * i, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
        imgInfo.image=[UIImage imageNamed:[NSString stringWithFormat:@"GuidancePic%d.jpg",i+1]];
        
        [scrollBG addSubview:imgInfo];
    }
    
    pageCol=[[UIPageControl alloc]initWithFrame:CGRectMake(0, SCREEN_HEIGHT - 30, 320, 20)];
    pageCol.numberOfPages = kfirstScrollNum;
    //pageCol.center=CGPointMake(SCREEN_WIDTH/2, SCREEN_HEIGHT-30);
    [self.view addSubview:pageCol];
    
    pageCol.hidden=YES;
    // Do any additional setup after loading the view from its nib.
}
- (void)scrollViewDidScroll:(UIScrollView *)sender
{
    
    int pageIndex = fabs(sender.contentOffset.x) /sender.frame.size.width;
    pageCol.currentPage = pageIndex;
    
    if (sender.contentOffset.x > (SCREEN_WIDTH * 2 + 60))
    {
        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"firstStart"];
        
        CustomTabBarViewController *_tabBarViewCol = [[CustomTabBarViewController alloc] init];
        AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate];
        app.window.rootViewController =_tabBarViewCol;
    }
    
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
